package com.qf.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author YDW
 * projectName:project2202_3
 * time:2022/5/13 11:19
 * description:
 */
public class MyInterceptor implements HandlerInterceptor {

    /**
     * 执行处理器方法之前执行
     * 登录拦截
     * @param request
     * @param response
     * @param handler
     * @return 如果返回true， 则放行， 如果返回false， 则拦截，后面的均不执行
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandler");
        return true;
    }

    /**
     * 执行处理器方法之后执行（执行返回值之前执行）
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle");
    }

    /**
     * 执行处理器方法完全执行完成之后(执行返回值)执行
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion");
    }
}
